﻿@using LanDBom.Resources
@{
    ViewBag.Title = "Custom";
}

<fieldset class="boun-m" style="width:96%">
    <legend class="len-x">@Resource.String762</legend>
    <div class="row ">
        <div class="form-group col-4">
            <label for="CL_number" class="col-lg-4 control-label">@Resource.String763</label>
            <div class="col-lg-10">
                <input type="text" class="form-control" id="txtnum" placeholder="@Resource.String763" name="num" maxlength="20" readonly="readonly">
            </div>
        </div>
        <div class="form-group col-4">
            <label for="CL_name" class="col-lg-4 control-label">@Resource.String764</label>
            <div class="col-lg-10 nav">
                <input type="text" class="form-control" id="txtname" placeholder="@Resource.String764" maxlength="100" name="name"><span style="color:red">*</span>
            </div>
        </div>
    </div>
    <div class="row ">
        <div class="form-group col-4">
            <label for="CL_address" class="col-lg-4 control-label">@Resource.String765</label>
            <div class="col-lg-10" style="display:flex">
                <input type="text" class="form-control" id="txtaddress" placeholder="@Resource.String216" name="address"maxlength="200"/><span style="color:red">*</span>
            </div>
        </div>
        <div class="form-group col-4">
            <label for="CL_phone" class="col-lg-4 control-label">@Resource.String766</label>
            <div class="col-lg-10 nav">
                <input type="tel" class="form-control" id="txtphone" placeholder="@Resource.String766" name="phone" maxlength="200"/><span style="color:red">*</span>
            </div>
        </div>
    </div>
    <div class="row ">
        <div class="form-group col-4">
            <label for="CL_email" class="col-lg-4 control-label">@Resource.String767</label>
            <div class="col-lg-10" style="display:flex">
                <input type="email" class="form-control" id="txtemail" placeholder="@Resource.String280" name="email" maxlength="50"/><span style="color:red">*</span>
            </div>
        </div>
        <div class="form-group col-4">
            <label for="CL_remarks" class="col-lg-4 control-label">@Resource.String768</label>
            <div class="col-lg-10 nav">
                <input type="text" class="form-control" id="txtremarks" placeholder="@Resource.String768" name="remarks">
            </div>
        </div>
    </div>
    <div class="row ">
        <div class="form-group col-4">
            <label for="CL_shipping_address" class="col-lg-4 control-label">@Resource.String769</label>
            <div class="col-lg-10">
                <input type="text" class="form-control" id="txtshipping_address" placeholder="@Resource.String769" name="shipping_address">
            </div>
        </div>
        <div class="form-group col-4">
            <label for="CL_distance" class="col-lg-4 control-label">@Resource.String770 (KM)</label>
            <div class="col-lg-10 nav">
                <input type="number" class="form-control" id="txtdistance" placeholder="@Resource.String770" name="distance" min="0">
            </div>
        </div>
    </div>

    <div class="row ">
        <div class="form-group col-4">
            <label for="CL_shipping_address" class="col-lg-4 control-label">助记码</label>
            <div class="col-lg-10">
                <input type="text" class="form-control" id="CL_zhu" placeholder="助记码" name="shipping_address"maxlength="50"/>
            </div>
        </div>
        <div class="form-group col-4">
            <label for="CL_distance" class="col-lg-4 control-label">所属法人</label>
            <div class="col-lg-10 nav">
                <input type="text" class="form-control" id="LC_fa" placeholder="所属法人" name="distance" min="0"maxlength="50"/>
            </div>
        </div>
    </div>
    <div class="row ">
        <div class="form-group col-4">
            <label for="CL_shipping_address" class="col-lg-4 control-label">货币</label>
            <div class="col-lg-10">
                <select id="CL_huo" class="form-control">
                    <option></option>
                </select>
            </div>
        </div>
        <div class="form-group col-4">
            <label for="CL_shipping_address" class="col-lg-4 control-label">简称</label>
            <div class="col-lg-10 nav">
                <input type="text" class="form-control" id="CL_JIank" placeholder="简称" name="shipping_address"maxlength="50"/>
            </div>
        </div>
    </div>
    <div class="row ">
        <div class="form-group col-4">
            <label for="CL_shipping_address" class="col-lg-4 control-label">国家</label>
            <div class="col-lg-10">
                <input type="text" name="Guojiad" value="" class="form-control" id="CL_Nation" list="Lod_sj"maxlength="50"/>
                <datalist id="Lod_sj" class="form-control" style="display:none">
                </datalist>
            </div>
        </div>
        <div class="form-group col-4">
            <label for="CL_shipping_address" class="col-lg-4 control-label">地区</label>
            <div class="col-lg-10 nav">
                <input type="text" name="CLkjie" value="" class="form-control" id="CL_District" list="Loishud_sj1" maxlength="50"/>
                <datalist id="Loishud_sj1" class="form-control" style="display:none">
                </datalist>
            </div>
        </div>
    </div>
    <div class="row ">
        <div class="form-group col-4">
            <label for="CL_shipping_address" class="col-lg-4 control-label">城市</label>
            <div class="col-lg-10">
                <input type="text" name="CLkunne" value="" class="form-control" id="CL_City" list="Loishud_sj2" maxlength="50"/>
                <datalist id="Loishud_sj2" class="form-control" style="display:none">
                </datalist>
            </div>
        </div>
        <div class="form-group col-4">
            <label for="CL_shipping_address" class="col-lg-4 control-label">终端客户</label>
            <div class="col-lg-10">
                <input type="text" name="CLkunne" value="" class="form-control" id="CL_ZDKH" maxlength="100"/>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-lg-2 "><input type="button" id="btnCreate" class="btn btn-light" value="确定" /> </div>
        <div class="col-lg-2"><button id="btnreset" type="submit" class="btn btn-light">重置</button></div>
        <div class="col-l-2"><button class="TUIhui btn btn-light">返回</button></div>
    </div>


</fieldset>


@section scripts
{

    <script src="~/Scripts/jquery-3.4.1.min.js"></script>
    <script src="~/Scripts/bootstrap.min.js"></script>

    <script>
        $(function () {
            $("#li16").css({ "color": "black", "background-color": "white" })
            var x = 10000
            var y = 99999
            var num = parseInt(Math.random() * (x - y + 1) + y)
            var afi = "KHBH" + num
            $("#txtnum").val(afi)//产生随机客户编号

        })
        $(function () {
            $("#btnreset").click(function () {

                var x = 10000
                var y = 99999
                var num = parseInt(Math.random() * (x - y + 1) + y)
                var afi = "KHBH" + num
                $("#txtnum").val(afi)//产生随机客户编号
            })
        })
        shiyong()
        function shiyong() {
            $.ajax({
                url: "/Custom/Profit",
                type: "POST",
                data: { "state": 4 },
                success: function (data) {
                    console.log(data)
                    $("#CL_huo option").remove();
                    $.each(data, function (i, item) {
                        var $tr = (`<option value="${item[0]}">${item[0]}</option>`);
                        $("#CL_huo").append($tr);
                    })
                },
                error: function (data) {
                    alert("erroer");
                },
            })
        }
        shiyong11()
        function shiyong11() {
            $.ajax({
                url: "/Custom/Custom",
                type: "POST",
                data: { "state": 1 },
                success: function (data) {
                    $("#Lod_sj option").remove();
                    $("#Loishud_sj1 option").remove();
                    $("#Loishud_sj2 option").remove();
                    $.each(data, function (i, item) {
                        var $TR = $(`<option value="${item[0]}">`);
                        switch (item[1]) {
                            case "地区":
                                $("#Loishud_sj1").append($TR)
                                break;
                            case "国家":
                                $("#Lod_sj").append($TR)
                                break;
                            case "城市":
                                $("#Loishud_sj2").append($TR)
                                break;
                            default:
                                break;
                        }
                    })
                },
                error: function (data) {
                    alert("erroer");
                },
            })
        }
        $(function () {
            $('#btnCreate').click(function () {
                var Custom = {
                    CL_bian: $('#txtnum').val(),
                    CL_name: "PC"+$('#txtname').val(),
                    CL_di: $('#txtaddress').val(),
                    CL_lian: $('#txtphone').val(),
                    CL_you: $('#txtemail').val(),
                    CL: $('#txtremarks').val(),
                    CL_bei: $('#txtshipping_address').val(),
                    CL_ju: $('#txtdistance').val(),
                    CL_Huobi: $('#CL_huo').val(),
                    CL_Jian: "PC"+$('#CL_JIank').val(),
                    CL_zhu: $('#CL_zhu').val(),
                    CL_shuo: $('#LC_fa').val(),
                    CL_City: $('#CL_City').val(),
                    CL_District: $('#CL_District').val(),
                    CL_Nation: $('#CL_Nation').val(),
                    CL_ZDKH: $("#CL_ZDKH").val()
                };
                if (Custom.CL_name == "") {
                    alert("客户名称不能为空！");
                } else if (Custom.CL_di == "") {
                    alert("公司地址不能为空！");
                } else if (Custom.CL_lian == "") {
                    alert("客户联系不能为空！");
                } else if (Custom.CL_you == "" && Custom.CL_ju == "" && Custom.CL_Huobi == "" && Custom.CL_Jian == "" && Custom.CL_zhu == "" && Custom.CL_shuo == "" && Custom.CL_City == "" && Custom.CL_District == "" && Custom.CL_Nation == "" && Custom.CL_ZDKH == ""  ) {
                    alert("输入框不能为空！");
                } else {
                    $.ajax({
                        url: "/Custom/AddClientele",
                        type: "POST",
                        data: Custom,
                        success: function (data) {
                            if (data == "添加成功") {
                                alert(data);
                                window.location.href = "/Application/CliView";
                            }
                        },
                        error: function (data) {
                            alert("erroer");
                        },
                    })
                }
            })
            $(".TUIhui").click(function () {
                history.go(-1)
            })
        })
    </script>

}
